﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Task_Network_Center.Reports;

namespace Task_Network_Center
{
    /// <summary>
    /// Logique d'interaction pour FrmTaskReport.xaml
    /// </summary>
    public partial class FrmTaskReport : Window
    {
        public FrmTaskReport()
        {
            InitializeComponent();
            _reportViewer.Load += ReportViewer_Load;
        }

        private bool _isReportViewerLoaded;

        private void ReportViewer_Load(object sender, EventArgs e)
        {
            if (!_isReportViewerLoaded)
            {
                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new
                Microsoft.Reporting.WinForms.ReportDataSource();
                MainDataSet dataset = new MainDataSet();

                dataset.BeginInit();

                reportDataSource1.Name = "DataSet1";
                

                reportDataSource1.Value = dataset.TableReport;
                this._reportViewer.LocalReport.DataSources.Add(reportDataSource1);

                string path;
                path = System.IO.Path.GetDirectoryName(
                   System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
                try
                {
                    string convertPath = path.Substring(6,path.Length -6);
                    string fullPath = convertPath + "\\Reports\\TaskReport.rdlc";
                    this._reportViewer.LocalReport.ReportPath = fullPath;
                }
                catch (Exception ex)
                {

                    MessageBox.Show("" + ex);
                }
                

                //this._reportViewer.LocalReport.ReportPath = "../../Reports\\TaskReport.rdlc";
                dataset.EndInit();

                

                MainDataSetTableAdapters.TableReportTableAdapter data = new MainDataSetTableAdapters.TableReportTableAdapter();



                data.ClearBeforeFill = true;
                data.Fill(dataset.TableReport);
                _reportViewer.RefreshReport();
                _isReportViewerLoaded = true;
                _reportViewer.ShowPrintButton = false;
            }
        }

    }
}
